package com.design.singleton.lazy.test;

import com.design.singleton.lazy.LazySingleton;

import java.util.concurrent.*;

/**
 * @Description: 测试
 * @Author: xiemiao
 * @CreateTime: 2023-07-06  09:50
 * @Version: 1.0
 */
public class Client {
    public static void main(String[] args) {
        // 创建线程池
        ThreadPoolExecutor executor = new ThreadPoolExecutor(
                8, // 核心线程数
                10, // 最大线程数
                20L, // 线程空闲时间
                TimeUnit.SECONDS, // 时间单位
                new ArrayBlockingQueue<>(16), // 任务队列
                Executors.defaultThreadFactory(), // 线程工厂
                new ThreadPoolExecutor.AbortPolicy() // 拒绝策略
        );

        Runnable runnable = () -> {
            LazySingleton singleton = LazySingleton.getInstance();
            System.out.println(Thread.currentThread().getName() + ": " + singleton.hashCode());
        };

        for (int i = 0; i < 20; i++) {
            executor.submit(runnable);
        }

        // 关闭线程池
        executor.shutdown();
    }
}
